<?php
// +----------------------------------------------------------------------
// | 幕小铺
// +----------------------------------------------------------------------
// | 版权所有 2016~2019 幕小铺科技（大连）有限公司 [ http://www.XXX.com ]
// +----------------------------------------------------------------------
// | 2020/03/14 jason wang
// +----------------------------------------------------------------------
namespace app\user_center\logic\user;
use think\facade\Hook;

use AlibabaCloud\Client\AlibabaCloud;
use AlibabaCloud\Client\Exception\ClientException;
use AlibabaCloud\Client\Exception\ServerException;

class VerifyMobile{


    private $keyId           = 'LTAI4GC6jWbCCCN6cS9mEBVm';//阿里云短信accessKeyId
    private $keyScret        = 'dbGJsaQ28tAL3EbNOBcSK10p5JJwVZ';//阿里云短信accessKeySecret

    /**
     * 一键登录，验证
     * @param  string $access_code      code
     * @author shiqiang <976162041@qq.com>
     * @return mixed
     */
    public function verifyMobile($access_code){
        /*if($mobile >= 14400000001 && $mobile <= 14499999999){
            return array_out(200, '登陆成功');
        }*/
        //阿里云发送短信
        AlibabaCloud::accessKeyClient($this -> keyId, $this -> keyScret)
            ->regionId('cn-hangzhou') //replace regionId as you need（这个地方是发短信的节点，默认即可，或者换成你想要的）
            ->asDefaultClient();

        try {
            $result = AlibabaCloud::rpc()
                ->product('Dypnsapi')
                 ->scheme('https') // https | http
                ->version('2017-05-25')
                ->action('GetMobile')
                ->method('POST')
                ->host('dypnsapi.aliyuncs.com')
                ->options([
                    'query' => [
                        'RegionId'      => "cn-hangzhou",
                        'AccessToken'   => $access_code,
                    ],
                ])
                ->request();
            $res = $result->toArray();
            if($res['Code'] == 'OK'){
                return array_out(200, $res['Message'], $res['GetMobileResultDTO']['Mobile']);
            }else{
                return array_out(-1001, $res['Message']);
            }
        } catch (ClientException $e) {
            return array_out(-1001, $e->getErrorMessage());
        } catch (ServerException $e) {
            return array_out(-1001, $e->getErrorMessage());
        }
    }
}